package net.maku.events.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import net.maku.framework.common.utils.PageResult;
import net.maku.framework.mybatis.service.impl.BaseServiceImpl;
import net.maku.events.convert.UserUnlockSiteConvert;
import net.maku.events.entity.UserUnlockSiteEntity;
import net.maku.events.query.UserUnlockSiteQuery;
import net.maku.events.vo.UserUnlockSiteVO;
import net.maku.events.dao.UserUnlockSiteDao;
import net.maku.events.service.UserUnlockSiteService;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 用户解锁站点
 *
 * @author 阿沐 babamu@126.com
 * @since 1.0.0 2025-03-22
 */
@Service
@AllArgsConstructor
public class UserUnlockSiteServiceImpl extends BaseServiceImpl<UserUnlockSiteDao, UserUnlockSiteEntity> implements UserUnlockSiteService {

    @Override
    public PageResult<UserUnlockSiteVO> page(UserUnlockSiteQuery query) {
        IPage<UserUnlockSiteEntity> page = baseMapper.selectPage(getPage(query), getWrapper(query));

        return new PageResult<>(UserUnlockSiteConvert.INSTANCE.convertList(page.getRecords()), page.getTotal());
    }

    private LambdaQueryWrapper<UserUnlockSiteEntity> getWrapper(UserUnlockSiteQuery query){
        LambdaQueryWrapper<UserUnlockSiteEntity> wrapper = Wrappers.lambdaQuery();
        return wrapper;
    }

    @Override
    public void save(UserUnlockSiteVO vo) {
        UserUnlockSiteEntity entity = UserUnlockSiteConvert.INSTANCE.convert(vo);

        baseMapper.insert(entity);
    }

    @Override
    public void update(UserUnlockSiteVO vo) {
        UserUnlockSiteEntity entity = UserUnlockSiteConvert.INSTANCE.convert(vo);

        updateById(entity);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(List<Long> idList) {
        removeByIds(idList);
    }

}